<?php
/*********
*    合作商控制器
*/
namespace Home\Controller;
use Home\Controller\HomeController;
class ShopsController extends HomeController {
 	public function _initialize(){
 		parent::_initialize();
 		
 	}
 	/**
 	 * 查询所有主分类
 	 */
	public function getShopsCat(){
		$cat = M('Shop_type')->where('pid ='."0")->select();
		$this->ajaxReturn($cat,'JSONP');
	}
 	/**
 	 * 查询子分类
 	 */
	public function getShopsCatByPid(){
	    $pid = I('pid');
		$cat = M('Shop_type')->where('pid ='.$pid)->select();
		$this->ajaxReturn($cat,'JSONP');
	}
	/**
	 * 根据分类获取合作商
	 */
	public function getShopsByCat(){
		$type_id = I('type_id')?I('type_id'):null;
		if($type_id != null){
			$where['type_id'] = $type_id;
		}
		$where['is_show'] = 1;
		$shops = M('Shop')->where($where)->select();
		$this->ajaxReturn($shops,'JSONP');
	}
	//合作商详情
	public function getDetails(){
		$shop_id = I('shop_id');
		$list = M('Shop')->where(array('shop_id'=>$shop_id))->find();
	    $list['pic']  = M('Shops_pic')->where(array('shops_id'=>$list['shop_id']))->select();
		$this->ajaxReturn($list,'JSONP');
	}
	//搜索合作商
	public function searchShops(){
		$keyword = I("keyword");
		$where['shop_name'] = array("like","%".$keyword."%");
		$shops = M('Shop')->where($where)->select();
		$this->ajaxReturn($shops,'JSONP');
	}
	
	
}
